package com.demo.es;

import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

import java.io.IOException;

/**
 * Hello world!
 */
public class ESTest_index_Delete_Batch {
    public static void main(String[] args) throws IOException {
        //创建Es客户端
        RestHighLevelClient esClient = new RestHighLevelClient(
                RestClient.builder(new HttpHost("192.168.100.7",9200))
        );

        //批量删除
        BulkRequest bulkRequest=new BulkRequest();
        bulkRequest.add(new DeleteRequest("user","1001"));
        bulkRequest.add(new DeleteRequest("user","1002"));
        bulkRequest.add(new DeleteRequest("user","1003"));

        BulkResponse response = esClient.bulk(bulkRequest, RequestOptions.DEFAULT);
        System.out.println(response.getItems());
        //关闭客户端
        esClient.close();
    }
}
